package com.mars.rabbitmq.ctrl;

import com.mars.fw.web.reponse.King;
import com.mars.rabbitmq.delay.KingOrderConsumer;
import com.mars.rabbitmq.delay.KingOrderProducer;
import com.mars.rabbitmq.delayPlugins.DelayPluginsProducer;
import com.mars.rabbitmq.normal.KingProducer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author King
 * @create 2020/8/19 17:12
 */
@Api(tags = "【RabbitMq】 测试接口")
@RestController
@RequestMapping(value = "/api/v1/mq")
public class KingRabbitMqController {

    @Autowired
    private KingProducer kingProducer;

    @Autowired
    private KingOrderProducer kingOrderProducer;

    @Autowired
    private DelayPluginsProducer delayPluginsProducer;

    @Autowired
    private KingOrderConsumer consumer;


    /**
     * 消息推送
     *
     * @param input
     * @return
     */
    @ApiOperation(value = "生产Normal消息")
    @PostMapping(value = "/produce")
    public King produce(@RequestBody KingRabbiMqDTO input) {
        kingProducer.send(input.getMessage());
        return King.success("success");
    }


    /**
     * 消息推送
     *
     * @param input
     * @return
     */
    @ApiOperation(value = "生产Delay消息")
    @PostMapping(value = "/orderProduce")
    public King orderProduce(@RequestBody KingRabbiMqDTO input) {
        kingOrderProducer.convertAndSend(input.getMessage());
        return King.success("success");
    }

    /**
     * 消息推送
     *
     * @param input
     * @return
     */
    @ApiOperation(value = "生产Delay消息--使用插件")
    @PostMapping(value = "/delayProduce")
    public King delayProduce(@RequestBody KingRabbiMqDTO input) {
        delayPluginsProducer.convertAndSend(input.getMessage(), input.getDelay());
        return King.success("success");
    }

    /**
     * 消息推送
     *
     * @return
     */
    @ApiOperation(value = "pull模式拉取消息")
    @PostMapping(value = "/onPull")
    public King onPull() {
        consumer.onPull();
        return King.success("success");
    }
}
